<?php
   
   define("BASECSS","Static/css/");     //定义css存储路径
   
   define("BASEJS","Static/js/");
   
   define("BASEIMG","Static/images/");  //定义图片存储路径
   
   $smarty = new Smarty();
   
   $smarty->config_dir      = "./App/common/libs/Config_File.class.php";
   
   $smarty->compile_dir     = "./BlockCompiled";
   
   $smarty->cache_dir       = "./BlockCash";
   
   $smarty->template_dir    = "./BlockTemplate";
   
   $smarty->caching         = false;
   
   $smarty->left_delimiter  = "<{";
   
   $smarty->right_delimiter = "}>";
   
   function css_tag($args){
   	$file = $args['file'];
	$cssPath ='<link href="'.BASECSS.$file.'" rel="stylesheet" />';
	return $cssPath;
   }
   
   function js_tag($args){
   	$file = $args['file'];
	$jsPath ='<script type="text/javascript" src="'.BASEJS.$file.'"></script>';
	return $jsPath;
   }
   
   function image_tag($args){
   	$file = $args['file'];
	$imagePath = '<img src="'.BASEIMG.$file.'" />';
	return $imagePath;
   }
   
   function block_display($args){
   	global $smarty;
	$smarty->register_function("block_display", "block_display");
	$smarty->register_function("css_tag", "css_tag");
	$smarty->register_function("js_tag", "js_tag");
	$smarty->register_function("image_tag", "image_tag");
   	$name = $args['id'];
	$block = DB::fetch_row("select *from `bb_block` as B left join `bb_block_template` as BT 
	                      on B.`templateid`=BT.`templateid` where B.`blockid`='{$name}' or B.`name`='{$name}'");
	$queryids  = explode("|",$block['queryid']);
	$vars      = explode("|",$block['var']);
	$nums      = explode("|",$block['num']);
	$categorys = explode("|",$block['category']);
	$i = 0;
	foreach($queryids as $queryid){
		$block_query = DB::fetch_row("select *from `bb_block_query` where `queryid`='$queryid'");
		$query_sql   = str_replace("{categoryid}",$categorys[$i],$block_query['content']);
		$query_sql   = str_replace("{num}",$nums[$i],$query_sql);
		$query_result= array();
		$query_result= DB::fetch_array($query_sql);
		$smarty->assign($vars[$i],$query_result);
		$i++;
	}
	$html = "index".$block['blockid'].".html";
	$smarty->display($html);
   }

?>